﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace QLTV.Forms.KeHoach
{
    public partial class frmKeHoach : BaseForm
    {
        public frmKeHoach()
        {
            InitializeComponent();
        }
        public bool isLongPlan { get; set; }
        public frmKeHoach(bool isLong)
        {
            InitializeComponent();
            //Phan biet 2 form ngan han va dai han
            isLongPlan = isLong;
            tblKeHoachTableAdapter.FillByLongPlan(dsLongPlan.tblKeHoach, isLong);
        }


        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            EditPlan();
        }
        private void EditPlan()
        {
            if (viewKeHoach.FocusedRowHandle > -1)
            {
                bool isLong = (bool)viewKeHoach.GetFocusedRowCellValue(colisLongPlan);
                if (isLong)
                {
                    frmLongPlanVessel f = new frmLongPlanVessel();
                    f.PlanID = (int)viewKeHoach.GetFocusedRowCellValue("Planid");
                    f.isNew = false;
                    f._refreshData = refreshData;
                    f.Show();
                    
                }
                else
                {
                    frmKeHoachNganHan f = new frmKeHoachNganHan();
                    f.PlanID = (int)viewKeHoach.GetFocusedRowCellValue("Planid");
                    f.isDone = Boolean.Parse(viewKeHoach.GetFocusedRowCellValue("isDone").ToString());
                    f.isNew = false;
                    f.Show();
                    f._refreshData = refreshData;
                }
            }
        }
        private void ViewPlan()
        {
            if (viewKeHoach.FocusedRowHandle > -1)
            {
                bool isLong = (bool)viewKeHoach.GetFocusedRowCellValue(colisLongPlan);
                if (isLong)
                {
                    frmLongPlanVessel f = new frmLongPlanVessel();
                    f.PlanID = (int)viewKeHoach.GetFocusedRowCellValue("Planid");
                    f.isNew = false;
                    f.isView = true;
                    f._refreshData = refreshData;
                    f.Show();

                }
                else
                {
                    frmKeHoachNganHan f = new frmKeHoachNganHan();
                    f.PlanID = (int)viewKeHoach.GetFocusedRowCellValue("Planid");
                    f.isDone = Boolean.Parse(viewKeHoach.GetFocusedRowCellValue("isDone").ToString());
                    f.isNew = false;
                    f.isView = true;
                    f.Show();
                    f._refreshData = refreshData;
                }
            }
        }
        public void refreshData()
        {
            tblKeHoachBindingSource.DataSource = tblKeHoachTableAdapter.GetData();
        }
        private void frmKeHoach_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsLongPlan.tblKeHoach' table. You can move, or remove it, as needed.
            this.tblKeHoachTableAdapter.Fill(this.dsLongPlan.tblKeHoach);

        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {


        }


        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (viewKeHoach.FocusedRowHandle > -1)
            {
                if (XtraMessageBox.Show(rm.GetString("sConfirm", myCultureInfo), rm.GetString("sMessageCaption", myCultureInfo), MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK)
                {
                    int planid = (int)viewKeHoach.GetFocusedRowCellValue("Planid");
                    tblKeHoachBindingSource.RemoveCurrent();
                    tblKeHoachTableAdapter.DeleteKeHoach(planid);
                    alertControl1.Show(this, rm.GetString("sMessageCaption", myCultureInfo), rm.GetString("sMessageSuccess", myCultureInfo));
                }
            }
        }

        private void radPlanType_EditValueChanged(object sender, EventArgs e)
        {
            // switch (((RadioGroup)(sender)).EditValue.ToString())
            if (((RadioGroup)(sender)).EditValue.ToString() == "all")
            {
                tblKeHoachBindingSource.Filter = "";
            }
            else if ((bool)((RadioGroup)(sender)).EditValue)
            {
                tblKeHoachBindingSource.Filter = "isLongPlan=1";

            }
            else
                tblKeHoachBindingSource.Filter = "isLongPlan=0";
        }

        private void viewKeHoach_DoubleClick(object sender, EventArgs e)
        {
            EditPlan();
        }
        //them moi dai hạn
        private void barButtonItem5_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            showDaiHan();
        }
        public void showDaiHan()
        {
            frmLongPlanVessel f = new frmLongPlanVessel();
            f.isNew = true;
            //islong plan binding
            f.AllowDrop = true;

            f.PlanID = Convert.ToInt32(tblKeHoachTableAdapter.NextID().ToString());
            f.Show();
            f._refreshData = refreshData;
        }

        //thêm mới ngắn hạn
        private void barButtonItem6_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ShowNganHan();
        }
        public void ShowNganHan()
        {
            frmKeHoachNganHan f = new frmKeHoachNganHan();
            f.isNew = true;
            //islong plan binding
            f.AllowDrop = false;
            f.isDone = false;
            f.PlanID = Convert.ToInt32(tblKeHoachTableAdapter.NextID().ToString());
            f.Show();
            f._refreshData = refreshData;
        }

        private void tblKeHoachBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            
        }

        private void cmdXem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            ViewPlan();
        }
    }
}